
//
//  LJHAllViewController.m
//  HEARME
//
//  Created by liujinhui on 16/1/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LJHDisAllViewController.h"
#import "LJHListViewController.h"
#import "LJHAnchorViewController.h"
#import "LJHCateScrollViewController.h"
#import "LJHAlbumsDetailViewController.h"
#import "LJHListDetailViewController.h"
#import "LJHSearchViewController.h"
#import "LJHSearchListViewController.h"
#import "LJHMoreListViewController.h"
#import "LJHMusicListViewController.h"
@interface LJHDisAllViewController ()<UIScrollViewDelegate,push,pushAll>

@property(nonatomic,retain)LJHBaseButton *btnRecommed;
@property(nonatomic,retain)LJHBaseButton *btnList;
@property(nonatomic,retain)LJHBaseButton *btnAuchor;
@property(nonatomic,retain)UIScrollView *bigScrollView;
@property(nonatomic,retain)UIView *sliderView;


@end

@implementation LJHDisAllViewController

-(void)viewWillAppear:(BOOL)animated
{

    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBarHidden = NO;

}

-(void)dealloc
{
    [_bigScrollView release];
    [_btnRecommed release];
    [_btnList release];
    [_btnAuchor release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"HearMe";
    [self createButtons];
 
    
    UIImage *image = [UIImage imageNamed:@"iconfont-sousuo-2.png"];
    UIImage *ima = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]initWithImage:ima style:UIBarButtonItemStylePlain target:self action:@selector(seachBtn:)];
    self.navigationItem.rightBarButtonItem = barBtn;
    
    [self setAutomaticallyAdjustsScrollViewInsets:NO];//设置不让scrollview适应高度
    self.bigScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, WIDTH, HEIGHT-111)];//内容scrollview
    self.bigScrollView.backgroundColor = [UIColor colorWithRed:0.655 green:1.000 blue:0.866 alpha:1.000];
    self.bigScrollView.contentSize = CGSizeMake(WIDTH*3, 40);
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.delegate = self;
    [self.view addSubview:self.bigScrollView];
    [_bigScrollView release];
    
    self.sliderView = [[UIView alloc] initWithFrame:CGRectMake(self.btnRecommed.frame.origin.x, self.btnRecommed.frame.origin.y+self.btnRecommed.frame.size.height, self.btnRecommed.frame.size.width, 2)];//滚动红线
    self.sliderView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.sliderView];
    [_sliderView release];
    
    self.reVC = [[LJHRecommendViewController alloc]init];
    [self.bigScrollView addSubview:self.reVC.view];
    self.reVC.myPush = self;
    
    LJHListViewController *liVC = [[LJHListViewController alloc]init];
    liVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);
    liVC.myPushAll = self;
    [self.bigScrollView addSubview:liVC.view];
    
    LJHAnchorViewController *anVC = [[LJHAnchorViewController alloc]init];
    anVC.view.frame = CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT);
    [self.bigScrollView addSubview:anVC.view];
    
    [self.bigScrollView setContentOffset:CGPointMake(0, 0)];//默认推荐页

    
    // Do any additional setup after loading the view.
}

#pragma mark - push系列

-(void)pushMoreListVC:(NSString *)myTitle//push到精品听单更多页
{
    
    LJHMoreListViewController *moreListVC = [[LJHMoreListViewController alloc] init];
    moreListVC.myTitle = myTitle;
    moreListVC.moreUrl = @"http://mobile.ximalaya.com/m/subject_list?device=iphone&page=1&per_page=10&title=更多";
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:moreListVC];
    
    [self.navigationController pushViewController:moreListVC animated:YES];
    [moreListVC release];
    
}

-(void)push:(NSString *)key contentType:(NSString *)contentType//push榜单详情页
{
    
    LJHListDetailViewController *listDetailVC = [[LJHListDetailViewController alloc] init];
    listDetailVC.key = key;
    listDetailVC.contentType = contentType;
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:listDetailVC];
    [self.navigationController pushViewController:listDetailVC animated:YES];
    [listDetailVC release];
    
}

-(void)push:(NSNumber *)categoryId//push到(听系列更多列表)
{
    
    LJHCateScrollViewController *moreView = [[LJHCateScrollViewController alloc]init];
    moreView.categoryId = categoryId;
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:moreView];
    [self.navigationController pushViewController:moreView animated:YES];
    [moreView release];
    
}

-(void)pushDetail:(NSString *)albumId :(NSString *)myTitle :(NSInteger)trackId//push到专辑详情页
{
    
    LJHAlbumsDetailViewController *albumDetail = [[LJHAlbumsDetailViewController alloc]init];
    albumDetail.navigationController.navigationBar.translucent = YES;
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:albumDetail];
    albumDetail.albumId = albumId;
    albumDetail.myTitle = myTitle;
    [self.navigationController pushViewController:albumDetail animated:YES];
    
    
}

-(void)pushMusicVC:(NSNumber *)num//push到精品听单详情页
{
    
    LJHMusicListViewController *musicListVC = [[LJHMusicListViewController alloc] init];
    musicListVC.specialId = num;
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:musicListVC];
    [self.navigationController pushViewController:musicListVC animated:YES];
    [musicListVC release];
    
}

-(void)createButtons//创建btn
{
    self.btnRecommed = [LJHBaseButton buttonWithType:UIButtonTypeCustom];
    self.btnRecommed.frame = CGRectMake(0, 0, WIDTH/3, 40);
    [self.btnRecommed setTitle:@"推荐" forState:UIControlStateNormal];
    [self.btnRecommed setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.btnRecommed.tag = 100;
    [self.btnRecommed addTarget:self action:@selector(recAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btnRecommed];
    
    self.btnList = [LJHBaseButton buttonWithType:UIButtonTypeCustom];
    self.btnList.frame = CGRectMake(WIDTH/3, 0, WIDTH/3, 40);
    [self.btnList setTitle:@"榜单" forState:UIControlStateNormal];
    [self.btnList setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.btnList addTarget:self action:@selector(lisAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btnList];
    
    self.btnAuchor = [LJHBaseButton buttonWithType:UIButtonTypeCustom];
    self.btnAuchor.frame = CGRectMake(WIDTH/3*2, 0, WIDTH/3, 40);
    [self.btnAuchor setTitle:@"主播" forState:UIControlStateNormal];
    [self.btnAuchor setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.btnAuchor addTarget:self action:@selector(aucAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btnAuchor];
}

-(void)presentPlay:(NSInteger)trackId arr:(NSMutableArray *)allMusicArray//点击scrollview头试图present音乐播放页面
{
    
    LJHPlayerViewController *player = [LJHPlayerViewController sharaMusicPlayer];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:player];
    player.song_id = trackId;
    player.allMusicArray = allMusicArray;
    player.indexRow = 0;
    [self presentViewController:naVC animated:YES completion:^{
    
     }];
    [naVC release];
    
}

#pragma mark - scroll协议方法

-(void)scrollViewDidScroll:(UIScrollView *)scrollView//scroll滑动
{
    
    self.sliderView.frame = CGRectMake(self.bigScrollView.contentOffset.x/3 , self.btnRecommed.frame.origin.y+self.btnRecommed.frame.size.height, self.btnRecommed.frame.size.width, 2);
    if (self.bigScrollView.contentOffset.x/WIDTH==0) {
        [self.btnRecommed setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.btnList setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btnAuchor setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    }
    
    if (self.bigScrollView.contentOffset.x/WIDTH==1) {
        [self.btnRecommed setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btnList setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.btnAuchor setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    }
    
    if (self.bigScrollView.contentOffset.x/WIDTH==2) {
        [self.btnRecommed setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btnList setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.btnAuchor setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }
    
    
}

#pragma mark - btn点击事件

-(void)recAction:(UIButton *)btn
{
    self.bigScrollView.contentOffset = CGPointMake(0, 0);
}

-(void)lisAction:(UIButton *)btn
{
    [self.bigScrollView setContentOffset:CGPointMake(WIDTH, 0)];
}

-(void)aucAction:(UIButton *)btn
{
    self.bigScrollView.contentOffset = CGPointMake(WIDTH*2, 0);
}

#pragma mark - seachBtn搜索按钮

-(void)seachBtn:(UIBarButtonItem *)barBtn
{
    
    LJHSearchListViewController *searchVC = [[LJHSearchListViewController alloc]init];
    [(LJHTabBarViewController *)self.tabBarController isHiddenTabBar:YES withViewController:searchVC];
    [self.navigationController pushViewController:searchVC animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
